package model.data;

import exceptions.UsernameException;
/**
 * 
 * @author Krystle
 *
 */
public class UsernameDescription {

  /**
   * La taille maximum de l'username
   */
  final static public int MAX_SIZE = 20;
  /**
   * La taille minimum de l'username
   */
  final static public int MIN_SIZE = 3;
	/**
	 * L'username
	 */
  private String login;
  
 
  public UsernameDescription(String username) throws UsernameException{
	  if( UsernameDescription.verifyUsername(username) == false) throw new UsernameException("UsernameDescription invalide");
	  
	  this.login = username;
          
  }
  
  /**
   * Copying a username
   * @param usernameDescription : the username to copy
   */
  public UsernameDescription(UsernameDescription usernameDescription)  {
    this.login = usernameDescription.getUsername();
   
  }
  
  /**
   * 
   * @return the username
   */
  public final String getUsername() {
	  return this.login;
  }
  
  /**
   * 
   */
    @Override
  public String toString() {
	  return this.getUsername();
  }
  /**
   * 
   */
  public boolean equals(Object o) {
	  return (this.getClass().isInstance(o) && this.getUsername().equals(((UsernameDescription)o).getUsername()));
  }
  
  /**
   * check a username
   * @param username the user login to check
   * @return true if check is succeed
   */
  static public boolean verifyUsername(String username) {
	return (username != null && username.length() >= UsernameDescription.MIN_SIZE && username.length() <= UsernameDescription.MAX_SIZE);
  }
  

}
